package a66weding.com.jiehuntong.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.util.HashMap;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.beans.CommonResultBean;
import a66weding.com.jiehuntong.beans.ErrorBean;
import a66weding.com.jiehuntong.beans.HttpRequestBean;
import a66weding.com.jiehuntong.beans.MarriageProposalBean;
import a66weding.com.jiehuntong.beans.SuccessBean;
import a66weding.com.jiehuntong.common.utils.CUtils;
import a66weding.com.jiehuntong.http.HttpHandleUtil;
import a66weding.com.jiehuntong.http.OnNetResultListener;
import a66weding.com.jiehuntong.http.RequestCode;
import a66weding.com.jiehuntong.http.UrlDealUtil;

/**
 * Created by admin on 2016/7/15.
 */
public class NoticeActivity extends Activity implements View.OnClickListener,OnNetResultListener {
    //任务内容;
    private String content ;
    private MarriageProposalBean.DataBean dataBean;
    //标题
    private TextView title;
    //任务title;
    private TextView task;
    //
    private TextView save;
    private EditText editText;
    private CommonResultBean bean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice);
        dataBean = (MarriageProposalBean.DataBean) getIntent().getSerializableExtra(JobDetail.TASK_FLAG);
        initView();
        initData();
    }

    private void initView(){
        title = (TextView) findViewById(R.id.title_tv);
        task = (TextView) findViewById(R.id.back_iamge);
        save = (TextView) findViewById(R.id.activity_notice_done);
        save.setOnClickListener(this);
        editText = (EditText) findViewById(R.id.activity_notice_editext);
    }

    private void initData(){
        title.setText("备注");
        task.setText(dataBean.getBookTitle()!=null?dataBean.getBookTitle():"");
        editText.setText(dataBean.getRemarks()==null?"":dataBean.getRemarks());
    }

    @Override
    public void onClick(View v) {
        content = editText.getText().toString();
        switch (v.getId()){
            case R.id.activity_notice_done:
                //网络数据上传;
                sendNotice();
                dataBean.setRemarks(content);
                Intent  intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putSerializable(JobDetail.TASK_FLAG,dataBean);
                intent.putExtras(bundle);
                setResult(6,intent);
                finish();
                break;
        }
    }

    @Override
    public void onSucess(SuccessBean sucessbean) {
           Object data =  sucessbean.getData();
        if (data instanceof CommonResultBean) {
            bean = (CommonResultBean) data;
            switch (bean.getResCode()) {
                case "0000":
                    //设置适配器
                    CUtils.showToast("上传成功了");
                    break;
            }
        }
    }

    @Override
    public void onError(ErrorBean errorBean) {

    }
    //网络上传数据;
    private void sendNotice(){

        String useUrl = UrlDealUtil.getRealUrlNoId("Update_Remarks")+"&i_Id="+dataBean.getMemberID();
        HashMap<String,String> paramsMap=new HashMap<>();
        paramsMap.put("BookTitle",dataBean.getBookTitle());
        paramsMap.put("Remarks",content);
        HttpRequestBean httpRequestBean = new HttpRequestBean(RequestCode.POSTEQUEST, useUrl, this, CommonResultBean.class, RequestCode.UPDATE_REMARKS, paramsMap);
        HttpHandleUtil.executeCommonPost(this,httpRequestBean);
    }


    //返回
    public void back(View view){
        Intent  intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putSerializable(JobDetail.TASK_FLAG,dataBean);
        intent.putExtras(bundle);
        setResult(6,intent);
        finish();
    }

}
